{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Microsoft Azure (detect face)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入需要的模块\n",
    "import requests\n",
    "import json\n",
    "\n",
    "# set to your own subscription key value\n",
    "subscription_key = '2306f093dc6d49ccbd40ef665bfc74b2'\n",
    "assert subscription_key\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'\n",
    "\n",
    "image_url = 'https://ww3.sinaimg.cn/bmiddle/61e7f4aaly1gde7tt19ltj20go0b6q3i.jpg'\n",
    "\n",
    "headers = {   \n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': '{}'.format(subscription_key),\n",
    "}\n",
    "\n",
    "data = {\n",
    "    'url': '{}'.format(image_url),\n",
    "}\n",
    "\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    'returnFaceAttributes': 'age,gender,glasses,emotion,hair', # 检测年龄性别、喜怒指数\n",
    "}\n",
    "\n",
    "r = requests.post(face_api_url,data=json.dumps(data),\n",
    "                  params=params,headers=headers)\n",
    "#print(json.dumps(response.json()))\n",
    "r.status_code #看状态码 200 成功！\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '37505c27-4307-46c9-876f-9768d5a11f3a',\n",
       "  'faceRectangle': {'top': 87, 'left': 33, 'width': 89, 'height': 89},\n",
       "  'faceAttributes': {'gender': 'male',\n",
       "   'age': 18.0,\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.002,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.025,\n",
       "    'neutral': 0.972,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'hair': {'bald': 0.03,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'gray', 'confidence': 0.24},\n",
       "     {'color': 'other', 'confidence': 0.11},\n",
       "     {'color': 'blond', 'confidence': 0.04},\n",
       "     {'color': 'red', 'confidence': 0.03}]}}},\n",
       " {'faceId': '7c7f3414-6f20-4cd6-9d16-3edc7b43488c',\n",
       "  'faceRectangle': {'top': 71, 'left': 306, 'width': 83, 'height': 83},\n",
       "  'faceAttributes': {'gender': 'male',\n",
       "   'age': 22.0,\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.999,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'hair': {'bald': 0.02,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.98},\n",
       "     {'color': 'gray', 'confidence': 0.22},\n",
       "     {'color': 'other', 'confidence': 0.14},\n",
       "     {'color': 'blond', 'confidence': 0.11},\n",
       "     {'color': 'red', 'confidence': 0.06}]}}},\n",
       " {'faceId': '52cf0412-2ba1-4015-9fbe-13ca02379867',\n",
       "  'faceRectangle': {'top': 76, 'left': 158, 'width': 82, 'height': 82},\n",
       "  'faceAttributes': {'gender': 'male',\n",
       "   'age': 22.0,\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.989,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.011},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'other', 'confidence': 0.8},\n",
       "     {'color': 'gray', 'confidence': 0.52},\n",
       "     {'color': 'brown', 'confidence': 0.27},\n",
       "     {'color': 'red', 'confidence': 0.03},\n",
       "     {'color': 'blond', 'confidence': 0.02}]}}}]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = r.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[{\"faceId\": \"37505c27-4307-46c9-876f-9768d5a11f3a\", \"faceRectangle\": {\"top\": 87, \"left\": 33, \"width\": 89, \"height\": 89}, \"faceAttributes\": {\"gender\": \"male\", \"age\": 18.0, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.002, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.025, \"neutral\": 0.972, \"sadness\": 0.0, \"surprise\": 0.0}, \"hair\": {\"bald\": 0.03, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 1.0}, {\"color\": \"brown\", \"confidence\": 0.99}, {\"color\": \"gray\", \"confidence\": 0.24}, {\"color\": \"other\", \"confidence\": 0.11}, {\"color\": \"blond\", \"confidence\": 0.04}, {\"color\": \"red\", \"confidence\": 0.03}]}}}, {\"faceId\": \"7c7f3414-6f20-4cd6-9d16-3edc7b43488c\", \"faceRectangle\": {\"top\": 71, \"left\": 306, \"width\": 83, \"height\": 83}, \"faceAttributes\": {\"gender\": \"male\", \"age\": 22.0, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.0, \"neutral\": 0.999, \"sadness\": 0.001, \"surprise\": 0.0}, \"hair\": {\"bald\": 0.02, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 0.98}, {\"color\": \"brown\", \"confidence\": 0.98}, {\"color\": \"gray\", \"confidence\": 0.22}, {\"color\": \"other\", \"confidence\": 0.14}, {\"color\": \"blond\", \"confidence\": 0.11}, {\"color\": \"red\", \"confidence\": 0.06}]}}}, {\"faceId\": \"52cf0412-2ba1-4015-9fbe-13ca02379867\", \"faceRectangle\": {\"top\": 76, \"left\": 158, \"width\": 82, \"height\": 82}, \"faceAttributes\": {\"gender\": \"male\", \"age\": 22.0, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.0, \"neutral\": 0.989, \"sadness\": 0.0, \"surprise\": 0.011}, \"hair\": {\"bald\": 0.11, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 1.0}, {\"color\": \"other\", \"confidence\": 0.8}, {\"color\": \"gray\", \"confidence\": 0.52}, {\"color\": \"brown\", \"confidence\": 0.27}, {\"color\": \"red\", \"confidence\": 0.03}, {\"color\": \"blond\", \"confidence\": 0.02}]}}}]'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json.dumps(r.json()) #字典转成json的格式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>眼镜</th>\n",
       "      <th>生气</th>\n",
       "      <th>蔑视</th>\n",
       "      <th>厌恶</th>\n",
       "      <th>恐惧</th>\n",
       "      <th>高兴</th>\n",
       "      <th>平静</th>\n",
       "      <th>伤心</th>\n",
       "      <th>惊讶</th>\n",
       "      <th>秃头程度</th>\n",
       "      <th>头发可见度</th>\n",
       "      <th>发色</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>面部ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>37505c27-4307-46c9-876f-9768d5a11f3a</th>\n",
       "      <td>male</td>\n",
       "      <td>18.0</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.025</td>\n",
       "      <td>0.972</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.03</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'black', 'confidence': 1.0}, {'colo...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7c7f3414-6f20-4cd6-9d16-3edc7b43488c</th>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.999</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.02</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'black', 'confidence': 0.98}, {'col...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52cf0412-2ba1-4015-9fbe-13ca02379867</th>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.989</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.011</td>\n",
       "      <td>0.11</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'black', 'confidence': 1.0}, {'colo...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        性别    年龄         眼镜   生气     蔑视   厌恶  \\\n",
       "面部ID                                                                           \n",
       "37505c27-4307-46c9-876f-9768d5a11f3a  male  18.0  NoGlasses  0.0  0.002  0.0   \n",
       "7c7f3414-6f20-4cd6-9d16-3edc7b43488c  male  22.0  NoGlasses  0.0  0.000  0.0   \n",
       "52cf0412-2ba1-4015-9fbe-13ca02379867  male  22.0  NoGlasses  0.0  0.000  0.0   \n",
       "\n",
       "                                       恐惧     高兴     平静     伤心     惊讶  秃头程度  \\\n",
       "面部ID                                                                          \n",
       "37505c27-4307-46c9-876f-9768d5a11f3a  0.0  0.025  0.972  0.000  0.000  0.03   \n",
       "7c7f3414-6f20-4cd6-9d16-3edc7b43488c  0.0  0.000  0.999  0.001  0.000  0.02   \n",
       "52cf0412-2ba1-4015-9fbe-13ca02379867  0.0  0.000  0.989  0.000  0.011  0.11   \n",
       "\n",
       "                                      头发可见度  \\\n",
       "面部ID                                          \n",
       "37505c27-4307-46c9-876f-9768d5a11f3a  False   \n",
       "7c7f3414-6f20-4cd6-9d16-3edc7b43488c  False   \n",
       "52cf0412-2ba1-4015-9fbe-13ca02379867  False   \n",
       "\n",
       "                                                                                     发色  \n",
       "面部ID                                                                                     \n",
       "37505c27-4307-46c9-876f-9768d5a11f3a  [{'color': 'black', 'confidence': 1.0}, {'colo...  \n",
       "7c7f3414-6f20-4cd6-9d16-3edc7b43488c  [{'color': 'black', 'confidence': 0.98}, {'col...  \n",
       "52cf0412-2ba1-4015-9fbe-13ca02379867  [{'color': 'black', 'confidence': 1.0}, {'colo...  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pandas.io.json import json_normalize\n",
    "\n",
    "df = pd.json_normalize(results)\n",
    "df = df.rename (columns = {\n",
    "                       \"faceId\":\"面部ID\",\n",
    "                       \"faceAttributes.gender\":\"性别\", \n",
    "                       \"faceAttributes.age\":\"年龄\",\n",
    "                       \"faceAttributes.glasses\":\"眼镜\",\n",
    "                       \"faceAttributes.emotion.anger\":\"生气\",\n",
    "                       \"faceAttributes.emotion.contempt\":\"蔑视\",\n",
    "                       \"faceAttributes.emotion.disgust\":\"厌恶\",\n",
    "                       \"faceAttributes.emotion.fear\":\"恐惧\",\n",
    "                       \"faceAttributes.emotion.happiness\":\"高兴\",\n",
    "                       \"faceAttributes.emotion.neutral\":\"平静\",\n",
    "                       \"faceAttributes.emotion.sadness\":\"伤心\",\n",
    "                       \"faceAttributes.emotion.surprise\":\"惊讶\",\n",
    "                       \"faceAttributes.hair.bald\":\"秃头程度\",\n",
    "                       \"faceAttributes.hair.invisible\":\"头发可见度\",\n",
    "                       \"faceAttributes.hair.hairColor\":\"发色\",})\n",
    "df = df.set_index('面部ID')\n",
    "df = df.iloc[:,4:]\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 一步步来 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceRectangle</th>\n",
       "      <th>faceAttributes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b45e14fd-7d5a-4d7b-975d-fd201ea0b6d4</td>\n",
       "      <td>{'top': 87, 'left': 33, 'width': 89, 'height':...</td>\n",
       "      <td>{'smile': 0.025, 'gender': 'male', 'age': 18.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9dde0856-4066-48fe-b34f-1dcb6660d2d5</td>\n",
       "      <td>{'top': 71, 'left': 306, 'width': 83, 'height'...</td>\n",
       "      <td>{'smile': 0.0, 'gender': 'male', 'age': 22.0, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8836e371-3b24-442d-8718-eef08ee3da1f</td>\n",
       "      <td>{'top': 76, 'left': 158, 'width': 82, 'height'...</td>\n",
       "      <td>{'smile': 0.0, 'gender': 'male', 'age': 22.0, ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId  \\\n",
       "0  b45e14fd-7d5a-4d7b-975d-fd201ea0b6d4   \n",
       "1  9dde0856-4066-48fe-b34f-1dcb6660d2d5   \n",
       "2  8836e371-3b24-442d-8718-eef08ee3da1f   \n",
       "\n",
       "                                       faceRectangle  \\\n",
       "0  {'top': 87, 'left': 33, 'width': 89, 'height':...   \n",
       "1  {'top': 71, 'left': 306, 'width': 83, 'height'...   \n",
       "2  {'top': 76, 'left': 158, 'width': 82, 'height'...   \n",
       "\n",
       "                                      faceAttributes  \n",
       "0  {'smile': 0.025, 'gender': 'male', 'age': 18.0...  \n",
       "1  {'smile': 0.0, 'gender': 'male', 'age': 22.0, ...  \n",
       "2  {'smile': 0.0, 'gender': 'male', 'age': 22.0, ...  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 做pd.DataFrame\n",
    "faces_data = results\n",
    "df = pd.DataFrame(faces_data)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    {'top': 87, 'left': 33, 'width': 89, 'height':...\n",
       "1    {'top': 71, 'left': 306, 'width': 83, 'height'...\n",
       "2    {'top': 76, 'left': 158, 'width': 82, 'height'...\n",
       "Name: faceRectangle, dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 抽变量 (pandas cheetsheet)\n",
    "df[\"faceRectangle\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {'top': 87, 'left': 33, 'width': 89, 'height': 89},\n",
       " 1: {'top': 71, 'left': 306, 'width': 83, 'height': 83},\n",
       " 2: {'top': 76, 'left': 158, 'width': 82, 'height': 82}}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"faceRectangle\"].to_dict() #转换成字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>left</th>\n",
       "      <td>33</td>\n",
       "      <td>306</td>\n",
       "      <td>158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>width</th>\n",
       "      <td>89</td>\n",
       "      <td>83</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>height</th>\n",
       "      <td>89</td>\n",
       "      <td>83</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         0    1    2\n",
       "top     87   71   76\n",
       "left    33  306  158\n",
       "width   89   83   82\n",
       "height  89   83   82"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(df[\"faceRectangle\"].to_dict()) #将上面的数据做成pandas的dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>top</th>\n",
       "      <th>left</th>\n",
       "      <th>width</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>87</td>\n",
       "      <td>33</td>\n",
       "      <td>89</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>71</td>\n",
       "      <td>306</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>76</td>\n",
       "      <td>158</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   top  left  width  height\n",
       "0   87    33     89      89\n",
       "1   71   306     83      83\n",
       "2   76   158     82      82"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(df[\"faceRectangle\"].to_dict()).T #横纵变向"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceRectangle_top</th>\n",
       "      <th>faceRectangle_left</th>\n",
       "      <th>faceRectangle_width</th>\n",
       "      <th>faceRectangle_height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>87</td>\n",
       "      <td>33</td>\n",
       "      <td>89</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>71</td>\n",
       "      <td>306</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>76</td>\n",
       "      <td>158</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   faceRectangle_top  faceRectangle_left  faceRectangle_width  \\\n",
       "0                 87                  33                   89   \n",
       "1                 71                 306                   83   \n",
       "2                 76                 158                   82   \n",
       "\n",
       "   faceRectangle_height  \n",
       "0                    89  \n",
       "1                    83  \n",
       "2                    82  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_rect = pd.DataFrame(df[\"faceRectangle\"].to_dict()).T\n",
    "# 各表头加上 faceRectangle_\n",
    "df_rect.columns = [ \"faceRectangle_\"+x for x in df_rect.columns]\n",
    "df_rect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceRectangle</th>\n",
       "      <th>faceAttributes</th>\n",
       "      <th>faceRectangle_top</th>\n",
       "      <th>faceRectangle_left</th>\n",
       "      <th>faceRectangle_width</th>\n",
       "      <th>faceRectangle_height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b45e14fd-7d5a-4d7b-975d-fd201ea0b6d4</td>\n",
       "      <td>{'top': 87, 'left': 33, 'width': 89, 'height':...</td>\n",
       "      <td>{'smile': 0.025, 'gender': 'male', 'age': 18.0...</td>\n",
       "      <td>87</td>\n",
       "      <td>33</td>\n",
       "      <td>89</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9dde0856-4066-48fe-b34f-1dcb6660d2d5</td>\n",
       "      <td>{'top': 71, 'left': 306, 'width': 83, 'height'...</td>\n",
       "      <td>{'smile': 0.0, 'gender': 'male', 'age': 22.0, ...</td>\n",
       "      <td>71</td>\n",
       "      <td>306</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8836e371-3b24-442d-8718-eef08ee3da1f</td>\n",
       "      <td>{'top': 76, 'left': 158, 'width': 82, 'height'...</td>\n",
       "      <td>{'smile': 0.0, 'gender': 'male', 'age': 22.0, ...</td>\n",
       "      <td>76</td>\n",
       "      <td>158</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId  \\\n",
       "0  b45e14fd-7d5a-4d7b-975d-fd201ea0b6d4   \n",
       "1  9dde0856-4066-48fe-b34f-1dcb6660d2d5   \n",
       "2  8836e371-3b24-442d-8718-eef08ee3da1f   \n",
       "\n",
       "                                       faceRectangle  \\\n",
       "0  {'top': 87, 'left': 33, 'width': 89, 'height':...   \n",
       "1  {'top': 71, 'left': 306, 'width': 83, 'height'...   \n",
       "2  {'top': 76, 'left': 158, 'width': 82, 'height'...   \n",
       "\n",
       "                                      faceAttributes  faceRectangle_top  \\\n",
       "0  {'smile': 0.025, 'gender': 'male', 'age': 18.0...                 87   \n",
       "1  {'smile': 0.0, 'gender': 'male', 'age': 22.0, ...                 71   \n",
       "2  {'smile': 0.0, 'gender': 'male', 'age': 22.0, ...                 76   \n",
       "\n",
       "   faceRectangle_left  faceRectangle_width  faceRectangle_height  \n",
       "0                  33                   89                    89  \n",
       "1                 306                   83                    83  \n",
       "2                 158                   82                    82  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用.join合并\n",
    "# 和原本的对比看看\n",
    "\n",
    "df.join(df_rect)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Face++ (detect face)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "api_secret = \"xQjc3VlWZ-TxoLtfZZyWu02ujJXYGBlN\"\n",
    "api_key = \"V7r1x1N4DvLxs3WXhJv68zvJ-tm8tG_6\"\n",
    "\n",
    "BASE_URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "img_url = 'https://wx4.sinaimg.cn/mw1024/acff3e61gy3g9pp2gqplyj20zk0zk1kx.jpg'\n",
    "\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,headpose,beauty', # 检测年龄性别，人脸姿势，颜值\n",
    "}\n",
    "\n",
    "r = requests.post(BASE_URL, params=payload, headers=headers)\n",
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1585812260,44cb7cd4-78f4-4065-8442-badd81f2fe63\",\"time_used\":1122,\"faces\":[{\"face_token\":\"e3d2ed2ddb8036e02feafeaf43eed534\",\"face_rectangle\":{\"top\":504,\"left\":412,\"width\":65,\"height\":65},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":41},\"headpose\":{\"pitch_angle\":3.4452312,\"roll_angle\":-7.982404,\"yaw_angle\":-18.243258},\"beauty\":{\"male_score\":50.675,\"female_score\":58.676}}},{\"face_token\":\"0c9770d269d9b9f169b8fddff24813e7\",\"face_rectangle\":{\"top\":629,\"left\":618,\"width\":63,\"height\":63},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":26},\"headpose\":{\"pitch_angle\":5.6223664,\"roll_angle\":-3.1341343,\"yaw_angle\":1.3319483},\"beauty\":{\"male_score\":52.069,\"female_score\":50.238}}},{\"face_token\":\"c94db7158965355fbefad93b4f2a6904\",\"face_rectangle\":{\"top\":578,\"left\":535,\"width\":61,\"height\":61},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":28},\"headpose\":{\"pitch_angle\":2.7005389,\"roll_angle\":13.872392,\"yaw_angle\":-6.7892346},\"beauty\":{\"male_score\":54.497,\"female_score\":55.485}}},{\"face_token\":\"552c1b90f32c208455ec5ad8abe6a95f\",\"face_rectangle\":{\"top\":483,\"left\":210,\"width\":58,\"height\":58},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":22},\"headpose\":{\"pitch_angle\":-6.591673,\"roll_angle\":28.303001,\"yaw_angle\":-31.273794},\"beauty\":{\"male_score\":61.984,\"female_score\":57.979}}},{\"face_token\":\"ed0dc40cf4681e36231b85d023a48017\",\"face_rectangle\":{\"top\":521,\"left\":295,\"width\":48,\"height\":48},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":20},\"headpose\":{\"pitch_angle\":2.4169426,\"roll_angle\":19.884186,\"yaw_angle\":-6.5474358},\"beauty\":{\"male_score\":49.895,\"female_score\":53.816}}},{\"face_token\":\"12f288590384a3f014253126950d090a\",\"face_rectangle\":{\"top\":523,\"left\":478,\"width\":42,\"height\":42}}],\"image_id\":\"//dBRI1otWuBiwwHgDE2DA==\",\"face_num\":6}\\n'"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content #可尝试将返回的内容放到http://jsonviewer.stack.hu/ 有结构化的看【记得删掉最前面和最后面没用的东西】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1585812260,44cb7cd4-78f4-4065-8442-badd81f2fe63',\n",
       " 'time_used': 1122,\n",
       " 'faces': [{'face_token': 'e3d2ed2ddb8036e02feafeaf43eed534',\n",
       "   'face_rectangle': {'top': 504, 'left': 412, 'width': 65, 'height': 65},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 41},\n",
       "    'headpose': {'pitch_angle': 3.4452312,\n",
       "     'roll_angle': -7.982404,\n",
       "     'yaw_angle': -18.243258},\n",
       "    'beauty': {'male_score': 50.675, 'female_score': 58.676}}},\n",
       "  {'face_token': '0c9770d269d9b9f169b8fddff24813e7',\n",
       "   'face_rectangle': {'top': 629, 'left': 618, 'width': 63, 'height': 63},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 26},\n",
       "    'headpose': {'pitch_angle': 5.6223664,\n",
       "     'roll_angle': -3.1341343,\n",
       "     'yaw_angle': 1.3319483},\n",
       "    'beauty': {'male_score': 52.069, 'female_score': 50.238}}},\n",
       "  {'face_token': 'c94db7158965355fbefad93b4f2a6904',\n",
       "   'face_rectangle': {'top': 578, 'left': 535, 'width': 61, 'height': 61},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 28},\n",
       "    'headpose': {'pitch_angle': 2.7005389,\n",
       "     'roll_angle': 13.872392,\n",
       "     'yaw_angle': -6.7892346},\n",
       "    'beauty': {'male_score': 54.497, 'female_score': 55.485}}},\n",
       "  {'face_token': '552c1b90f32c208455ec5ad8abe6a95f',\n",
       "   'face_rectangle': {'top': 483, 'left': 210, 'width': 58, 'height': 58},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 22},\n",
       "    'headpose': {'pitch_angle': -6.591673,\n",
       "     'roll_angle': 28.303001,\n",
       "     'yaw_angle': -31.273794},\n",
       "    'beauty': {'male_score': 61.984, 'female_score': 57.979}}},\n",
       "  {'face_token': 'ed0dc40cf4681e36231b85d023a48017',\n",
       "   'face_rectangle': {'top': 521, 'left': 295, 'width': 48, 'height': 48},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 20},\n",
       "    'headpose': {'pitch_angle': 2.4169426,\n",
       "     'roll_angle': 19.884186,\n",
       "     'yaw_angle': -6.5474358},\n",
       "    'beauty': {'male_score': 49.895, 'female_score': 53.816}}},\n",
       "  {'face_token': '12f288590384a3f014253126950d090a',\n",
       "   'face_rectangle': {'top': 523, 'left': 478, 'width': 42, 'height': 42}}],\n",
       " 'image_id': '//dBRI1otWuBiwwHgDE2DA==',\n",
       " 'face_num': 6}"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = r.json() #requests模块巧妙的方法-变成字典\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"request_id\": \"1585812260,44cb7cd4-78f4-4065-8442-badd81f2fe63\", \"time_used\": 1122, \"faces\": [{\"face_token\": \"e3d2ed2ddb8036e02feafeaf43eed534\", \"face_rectangle\": {\"top\": 504, \"left\": 412, \"width\": 65, \"height\": 65}, \"attributes\": {\"gender\": {\"value\": \"Female\"}, \"age\": {\"value\": 41}, \"headpose\": {\"pitch_angle\": 3.4452312, \"roll_angle\": -7.982404, \"yaw_angle\": -18.243258}, \"beauty\": {\"male_score\": 50.675, \"female_score\": 58.676}}}, {\"face_token\": \"0c9770d269d9b9f169b8fddff24813e7\", \"face_rectangle\": {\"top\": 629, \"left\": 618, \"width\": 63, \"height\": 63}, \"attributes\": {\"gender\": {\"value\": \"Female\"}, \"age\": {\"value\": 26}, \"headpose\": {\"pitch_angle\": 5.6223664, \"roll_angle\": -3.1341343, \"yaw_angle\": 1.3319483}, \"beauty\": {\"male_score\": 52.069, \"female_score\": 50.238}}}, {\"face_token\": \"c94db7158965355fbefad93b4f2a6904\", \"face_rectangle\": {\"top\": 578, \"left\": 535, \"width\": 61, \"height\": 61}, \"attributes\": {\"gender\": {\"value\": \"Female\"}, \"age\": {\"value\": 28}, \"headpose\": {\"pitch_angle\": 2.7005389, \"roll_angle\": 13.872392, \"yaw_angle\": -6.7892346}, \"beauty\": {\"male_score\": 54.497, \"female_score\": 55.485}}}, {\"face_token\": \"552c1b90f32c208455ec5ad8abe6a95f\", \"face_rectangle\": {\"top\": 483, \"left\": 210, \"width\": 58, \"height\": 58}, \"attributes\": {\"gender\": {\"value\": \"Female\"}, \"age\": {\"value\": 22}, \"headpose\": {\"pitch_angle\": -6.591673, \"roll_angle\": 28.303001, \"yaw_angle\": -31.273794}, \"beauty\": {\"male_score\": 61.984, \"female_score\": 57.979}}}, {\"face_token\": \"ed0dc40cf4681e36231b85d023a48017\", \"face_rectangle\": {\"top\": 521, \"left\": 295, \"width\": 48, \"height\": 48}, \"attributes\": {\"gender\": {\"value\": \"Female\"}, \"age\": {\"value\": 20}, \"headpose\": {\"pitch_angle\": 2.4169426, \"roll_angle\": 19.884186, \"yaw_angle\": -6.5474358}, \"beauty\": {\"male_score\": 49.895, \"female_score\": 53.816}}}, {\"face_token\": \"12f288590384a3f014253126950d090a\", \"face_rectangle\": {\"top\": 523, \"left\": 478, \"width\": 42, \"height\": 42}}], \"image_id\": \"//dBRI1otWuBiwwHgDE2DA==\", \"face_num\": 6}'"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json.dumps(r.json()) #字典转成json的字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas.io.json import json_normalize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_num</th>\n",
       "      <th>faces</th>\n",
       "      <th>image_id</th>\n",
       "      <th>request_id</th>\n",
       "      <th>time_used</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6</td>\n",
       "      <td>[{'face_token': 'e3d2ed2ddb8036e02feafeaf43eed...</td>\n",
       "      <td>//dBRI1otWuBiwwHgDE2DA==</td>\n",
       "      <td>1585812260,44cb7cd4-78f4-4065-8442-badd81f2fe63</td>\n",
       "      <td>1122</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   face_num                                              faces  \\\n",
       "0         6  [{'face_token': 'e3d2ed2ddb8036e02feafeaf43eed...   \n",
       "\n",
       "                   image_id                                       request_id  \\\n",
       "0  //dBRI1otWuBiwwHgDE2DA==  1585812260,44cb7cd4-78f4-4065-8442-badd81f2fe63   \n",
       "\n",
       "   time_used  \n",
       "0       1122  "
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = json_normalize(results)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 腾讯云 (compare)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "api_secret = 'AKID94CArHRGrSmq41tijT0HJSTEzUkjosGf'\n",
    "api_key = 'eDg14qM2Qu85mAVidH2WjeIgnhTJtCD1'\n",
    "\n",
    "BASE_URL = 'https://iai.tencentcloudapi.com'\n",
    "img_url_1 = 'https://wx1.sinaimg.cn/mw1024/acff3e61gy3g9pp2gufnij20zk0zkkf9.jpg'\n",
    "img_url_2 = 'https://wx1.sinaimg.cn/mw1024/acff3e61gy1g9n19vrp56j22yo3nab2c.jpg'\n",
    "Action = 'CompareFace'\n",
    "\n",
    "headers = {\n",
    "    'Version' : '2018-03-01',\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "\n",
    "payload = {\n",
    "    \"image_url_1\":img_url_1,\n",
    "    \"image_url_2\":img_url_2,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "}\n",
    "\n",
    "r = requests.post(BASE_URL, Action, params=payload, headers=headers)\n",
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Response': {'Error': {'Code': 'InvalidParameter',\n",
       "   'Message': 'Url key and value should be splited by `=`.'},\n",
       "  'RequestId': '6f081ec8-1a2a-49fe-8808-c2b08f1928d5'}}"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.json_normalize(results,record_path='faces')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
